home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Rice_CMS / gopher24 / gopherdh.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1992-06-25  |  4.9 KB  |  184 lines

  1. /*
  2.  *        Name: GOPHERDH REXX
  3.  *              pipeline stage for interpreting the CMS HELP database
  4.  *      Author: Rick Troth, Rice Univ, I/S VM Systems Support
  5.  *        Date: 1992-Apr-25, Jun-24
  6.  *
  7.  *              This gem is supplied with Rice CMS GopherD.
  8.  */
  9.  
  10. /*  accept a command line;  remember options  */
  11. Parse Upper Arg item '(' opts
  12.  
  13. /*  the "item" may have leading "path" parts,  which we just ignore   */
  14. Do While Index(item,'/') > 0; Parse Var item . '/' item; End
  15.  
  16. /*  make it right  */
  17. If Words(item) = 0 Then item = "TASK HELP"
  18. If Words(item) = 1 Then topic = "CMS"
  19.                    Else Parse Var item topic item .
  20.  
  21. /*  is it a task? menu? or leaf item?  */
  22. If item = "TASK" Then Do; item = topic; topic = "TASK"; End
  23. If item = "MENU" Then Do; item = topic; topic = "MENU"; End
  24.  
  25. /*  call the right pipeline stages  */
  26. Select  /*  topic  */
  27.  
  28.     When topic = "TASKTEXT" Then Call HELPTEXT
  29.     When topic = "MENUTEXT" Then Call HELPTEXT
  30.  
  31.     When topic = "TASK" Then Call HELPTASK
  32. /*      'CALLPIPE DISK' item 'HELPTASK * | HELPTASK' item '| *:'      */
  33.  
  34.     When topic = "MENU" Then CALL HELPMENU
  35. /*      'CALLPIPE DISK' item 'HELPMENU * | HELPMENU' item '| *:'      */
  36.  
  37.     Otherwise                CALL HELPITEM
  38. /*      'CALLPIPE COMMAND HELP' topic item '(NOSCREEN' opts '| *:'    */
  39.  
  40.     End  /*  Select  topic  */
  41.  
  42. Exit
  43.  
  44.  
  45.  
  46. /* ------------------------------------------------------------ HELPITEM
  47.  */
  48. HELPITEM:
  49.  
  50. 'CALLPIPE COMMAND HELP' topic item '(NOSCREEN' opts '| *:'
  51.  
  52. Return
  53.  
  54.  
  55.  
  56. /* ------------------------------------------------------------ HELPTEXT
  57.  */
  58. HELPTEXT:
  59.  
  60. /*  it would be way-cool if we could present the preliminary text     *
  61.  *  ("user instructions",  or whatever you want to call it)           *
  62.  *  as a plain-text item from the menu we're creating here.           */
  63.  
  64. If topic = "MENUTEXT" Then 'ADDPIPE DISK' item 'HELPMENU * | *.INPUT:'
  65.                       Else 'ADDPIPE DISK' item 'HELPTASK * | *.INPUT:'
  66.  
  67. /* read and replay displayed text or "user instructions" from task */
  68. 'PEEKTO LINE'
  69. Do While rc = 0
  70.     If Strip(line) = "" & Strip(prev) = "" Then Leave
  71.  
  72.     If Left(line,1) ^= '.' Then Do
  73.         /* remove any HELP control sequences */
  74.         p = Index(line,'4A'x)
  75.         Do While p > 0
  76.             line = Left(line,p-1) || Substr(line,p+2)
  77.             p = Index(line,'4A'x)
  78.             End
  79.         /* and send this line of text down the pipe */
  80.         'OUTPUT' line
  81.         End
  82.  
  83.     prev = line
  84.     'READTO'
  85.     'PEEKTO LINE'
  86.     End  /*  Do  While  */
  87.  
  88. Return
  89.  
  90.  
  91.  
  92. /* ------------------------------------------------------------ HELPTASK
  93.  */
  94. HELPTASK:
  95.  
  96. 'ADDPIPE DISK' item 'HELPTASK * | *.INPUT:'
  97.  
  98. /* first consume the displayed text or "user instructions" */
  99. 'PEEKTO LINE'
  100. Do While rc = 0
  101.     If Strip(line) = "" & Strip(prev) = "" Then Leave
  102. /*  If Left(line,1) ^= '.' Then 'OUTPUT' line  */
  103.     prev = line
  104.     'READTO'
  105.     'PEEKTO LINE'
  106.     End  /*  Do  While  */
  107.  
  108. 'OUTPUT' "0" || item "task heading text" || '05'x || ,
  109.          "0" || "TASKTEXT" item
  110.  
  111. /* now interpret the task lines and make a menu */
  112. 'PEEKTO LINE'
  113. Do While rc = 0
  114.     If Left(line,1) ^= '.' & Strip(line) ^= "" Then Do
  115.         /* ignoring blank lines and control lines */
  116.         Parse Var line 1 path 25 title
  117.  
  118.         /* remove HELP control sequences from titles */
  119.         p = Index(title,'4A'x)
  120.         Do While p > 0
  121.             title = Left(title,p-1) || Substr(title,p+2)
  122.             p = Index(title,'4A'x)
  123.             End
  124.  
  125.         type = "0"
  126.         Parse Upper Var path topic item .
  127.         If item = "TASK" Then Do; item = topic; topic = "TASK"; End
  128.         If item = "MENU" Then Do; item = topic; topic = "MENU"; End
  129.         If topic = "TASK" | topic = "MENU" Then type = "1"
  130.         'OUTPUT' type || title || '05'x || type || topic item
  131. /*      'OUTPUT' type || title || '05'x || type || path               */
  132.         End  /*  If  ..  Do  */
  133.  
  134.     'READTO'
  135.     'PEEKTO LINE'
  136.     End  /*  Do  While  */
  137.  
  138. Return
  139.  
  140.  
  141.  
  142. /* ------------------------------------------------------------ HELPMENU
  143.  */
  144. HELPMENU:
  145.  
  146. 'ADDPIPE DISK' item 'HELPMENU * | *.INPUT:'
  147.  
  148. topic = item
  149.  
  150. 'PEEKTO LINE'
  151. Do While rc = 0
  152.     If Strip(line) = "" & Strip(prev) = "" Then Leave
  153.     prev = line
  154.     'READTO'
  155.     'PEEKTO LINE'
  156.     End  /*  Do  While  */
  157.  
  158. 'OUTPUT' "0" || item "menu heading text" || '05'x || ,
  159.          "0" || "MENUTEXT" item
  160.  
  161. 'PEEKTO LINE'
  162. Do While rc = 0
  163.     If Left(line,1) ^= '.' & Strip(line) ^= "" Then Do
  164.         Parse Var line item .
  165.         key = Left(item,1)
  166.         Select  /*  key  */
  167.             When key = '*' Then
  168.                 'OUTPUT' "1" || line || '05'x ||  ,
  169.                     "1" || "MENU" Substr(item,2)
  170.             When key = ':' Then
  171.                 'OUTPUT' "1" || line || '05'x || ,
  172.                     "1" || "TASK" Substr(item,2)
  173.             Otherwise
  174.                 'OUTPUT' "0" || line || '05'x || ,
  175.                     "0" || topic item
  176.             End  /*  Select  key  */
  177.         End  /*  If  ..  Do  */
  178.     'READTO'
  179.     'PEEKTO LINE'
  180.     End  /*  Do  While  */
  181.  
  182. Return
  183.  
  184.